package cn.train.controler;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.train.model.Admin;
import cn.train.model.UserTable;
import cn.train.service.AdminServices;
import cn.train.service.UserTableService;
import cn.train.util.Pageutil;

@WebServlet("/BackGuanliServlet")
public class BackGuanliServlet extends HttpServlet {
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String page=req.getParameter("pageIndex");
		int pageIndex=1;
		
		if(page==null) {
			page="1";
		}
		pageIndex=Integer.parseInt(page);
		AdminServices admin=new AdminServices();
	
		int count=admin.getCount();
		Pageutil pu=new Pageutil();
		
		int totalPage=pu.getTotalPage(count, Pageutil.pageSize);
		
	    if(pageIndex<1) {
					pageIndex = 1;
	    }else if(pageIndex>totalPage) {
					pageIndex = totalPage;
		}
		List<Admin> list=admin.AllAdmin(pageIndex, Pageutil.pageSize);
		req.setAttribute("list", list);
		req.setAttribute("pageIndex", pageIndex);
		req.setAttribute("totalPage", totalPage);
		
		req.getRequestDispatcher("back/Admin.jsp").forward(req, resp);
	}
	
	
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	     doGet(req,resp);
	}
}
